package SwingWorkers;

import GUIClient.GUIExtraFunctions;
import GUIClient.GUIOperationInProgress;
import java.io.BufferedReader;
import java.io.PrintWriter;
import javax.swing.JTextPane;
import javax.swing.JTree;
import javax.swing.SwingWorker;

public class SwingWorkerCreateTree extends SwingWorker<Boolean, Void> {

    GUIOperationInProgress progress = new GUIOperationInProgress();
    BufferedReader in;
    PrintWriter out;
    boolean server;
    String text;
    JTextPane textPane;
    JTree tree;

    public SwingWorkerCreateTree(JTree treeFinal, JTextPane pane, String textField, boolean isServer,
            BufferedReader input, PrintWriter output) {
        tree = treeFinal;
        textPane = pane;
        text = textField;
        server = isServer;
        in = input;
        out = output;
    }

    @Override
    protected Boolean doInBackground() throws Exception {
        progress.setVisible(true);
        GUIExtraFunctions.updateTextPane(textPane, "Actualizando Árbol de Directorios (" + text + ")");
        tree.setModel(GUIExtraFunctions.treeFinal(text, server, in, out));
        GUIExtraFunctions.updateTextPane(textPane, "Árbol de Directorios Actualizado");
        progress.setVisible(false);
        return true;
    }
}
